﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MastePage/SubEmptyMaster.Master" AutoEventWireup="true" CodeBehind="PurchaseEdit.aspx.cs" Inherits="BySoft.Web.Site.StockManage.PurchaseEdit" %>

<%@ MasterType VirtualPath="~/MastePage/SubEmptyMaster.master" %>
<%@ Register Assembly="OneSoft.Web" Namespace="OneSoft.Web.UI.WebControls" TagPrefix="asp" %>
<%@ Register Assembly="BySoft.Web.Controls" Namespace="BySoft.Web.Controls" TagPrefix="cc1" %>
<asp:Content ID="cphHeadContent" runat="server" ContentPlaceHolderID="HeadPlace">
    <script type="text/javascript">
        $(function () {
            $("#tabs").tabs({ show: function (event, ui) { iframeAutoFit(); } });
        })

        function CheckNumWithDotOne(txtBox) {
            if (txtBox != null && txtBox.value != "") {
                var numFormat = /(^[0-9]\d{0,9}(\.\d{0,4})?$)/;
                var text = txtBox.value;
                if (!numFormat.test(text)) {
                    txtBox.value = 0;
                }
            }
        }

        function Refreashtab() {
            $("#tabs").tabs({ show: function (event, ui) { iframeAutoFit(); } });
        }

        function importNewRow(IsRquisition) {
            var billid = $("#<%=lblBillID.ClientID%>").text();
            ShowTopDialog('新增', '../ComPage/QueryMMaterialByPurchase.aspx?isrquisition=' + IsRquisition + '&rid=' + billid, 'NewDetail();', 800, 600); return false;
        }

        function NewDetail() {
            var str = getCookie(dialogReturn_key);
            if (str != null && str == "success") {
                $("#<%=btnAddh.ClientID %>").click();
        }
        setCookie(dialogReturn_key, "");
    }

    function OpenSupplier() {
        ShowTopDialog('选择厂商', '../ComPage/QuerySSupplier.aspx', 'FillSupplier();', 850, 600); return false;
    }

    function FillSupplier() {
        var str = getCookie(dialogReturn_key);
        if (str != null && str != "") {
            str = decodeURIComponent(str);
            var arrTmp = str.split(",");
            if (undefined != arrTmp[0]) {
                document.getElementById("<%=txtSupplierID.ClientID%>").value = arrTmp[0];
                }
            if (undefined != arrTmp[1]) {
                document.getElementById("<%=txtSupplierName.ClientID%>").value = arrTmp[1];
            }
            }
            setCookie(dialogReturn_key, "");

    }
        function changeNum(obj,str) {
            var pre = obj.id.replace(str, "");
            var nums = $("#" + pre + "txtNums").val() * 1;
            var price = $("#" + pre + "txtPrice").val() * 1;
            
            $("#" + pre + "txtAmount").val((nums * price).toFixed(2));
            if (str == "txtNums") {
                var singlemmnumber = $("#" + pre + "lblSingleMMNumber").text() * 1;
                $("#" + pre + "txtMMNumber").val((nums * singlemmnumber).toFixed(2))
            }
        }
    </script>
    </asp:Content>
    <asp:Content ID="cphContent" runat="server" ContentPlaceHolderID="EmptyMasteCPH">
    <h1 class="tit">库存管理 >> <a href="PurchaseList.aspx">材料采购单</a> >> 编辑</h1>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div class="tableStyle2">
                <table cellpadding="0" cellspacing="0" id="tBase" runat="server">
                    <tr>
                        <th class="left2">表单号码：
                        </th>
                        <td class="right2">
                            <asp:Label CssClass="lblreadonly" ID="lblBillID" runat="server"></asp:Label>
                        </td>
                        <th class="left2">日期：
                        </th>
                        <td class="right2">
                            <input class="Wdate" id="cpBillDate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="true" runat="server" type="text"></input>
                        </td>
                    </tr>
                    <tr>
                        <th class="left2">厂商编号：
                        </th>
                        <td class="right2">
                            <asp:TextBox CssClass="lblreadonly" ID="txtSupplierID" runat="server"></asp:TextBox>
                            <a onclick="OpenSupplier();">
                                <img src="../App_Themes/Common_CSS/images/GridDetail.gif" alt="" />
                            </a>
                            <span style="color: Red">*</span>
                            <asp:RequiredFieldValidator ControlToValidate="txtSupplierID" Display="None" ErrorMessage="请选择厂商！" ID="rfvSupplierID" ValidationGroup="gSubmit" runat="server"></asp:RequiredFieldValidator>
                        </td>
                        <th class="left2">厂商名称：
                        </th>
                        <td class="right2">
                            <asp:TextBox CssClass="lblreadonly" ID="txtSupplierName" ReadOnly="true" runat="server"></asp:TextBox>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="tableStyle">
                <div id="tabs">
                    <ul>
                        <li><a href="#tabs-1">明细</a></li>
                    </ul>
                    <div id="tabs-1" class="tableStyle">
                        <div style="text-align: right; width: 100%; padding-bottom: 10px">
                            <label class="btnStylec png_bg">
                                <asp:Button ID="btnAdd" runat="server" Text="新增" OnClick="btnAdd_Click" />
                            </label>
                            <label class="btnStylec png_bg">
                                <asp:Button ID="btnRquisition" runat="server" Text="请购单" OnClick="btnRquisition_Click" />
                            </label>
                            <label class="btnStylec png_bg">
                                <asp:Button ID="btnAddh" runat="server" CssClass="Hidden" OnClick="btnAddh_Click" />
                            </label>
                        </div>
                        <div class="divscroll">
                            <asp:SGridView runat="server" ID="grdResult" Width="100%" ShowActionToolBar="false"
                                OnRowDataBound="grdResult_RowDataBound" OnRowCommand="grdResult_RowCommand" AutoGenerateColumns="false"
                                AllowCascade="false">
                                <Columns>
                                    <asp:TemplateField HeaderStyle-CssClass="Hidden" ItemStyle-CssClass="Hidden" FooterStyle-CssClass="Hidden">
                                        <HeaderTemplate>
                                            BillDetailID
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblBillDetailID" runat="server" Text='<%#Eval("BillDetailID") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            序号
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblOrderNum" runat="server" Text='<%#Eval("OrderNum") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderStyle-CssClass="Hidden" ItemStyle-CssClass="Hidden" FooterStyle-CssClass="Hidden">
                                        <HeaderTemplate>
                                            RquisitionDetailID
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblRquisitionDetailID" runat="server" Text='<%#Eval("RquisitionDetailID") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            请购单号
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblRquisitionID" runat="server" Text='<%#Eval("RquisitionID") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            工令号
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblWorkOrderNo" runat="server" Text='<%#Eval("WorkOrderNo") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            原料编号
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblMaterialID" runat="server" Text='<%#Eval("MaterialID") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            原料品名
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblMaterialName" runat="server" Text='<%#Eval("MaterialName") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            规格
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblSpecifications" runat="server" Text='<%#Eval("Specifications") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            单位
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblUnit" runat="server" Text='<%#Eval("Unit") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            需求数量
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblRquisitionNums" runat="server" Text='<%#Eval("RquisitionNums") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            剩余数量
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblResNum" runat="server" Text='<%#Eval("ResNum") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            数量
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:TextBox CssClass="fullWidth" ID="txtNums" Width="80px" runat="server" onkeyup="CheckNumWithDot(this);changeNum(this,'txtNums');" Text='<%#Eval("Nums") %>'></asp:TextBox>
                                            <asp:RegularExpressionValidator ControlToValidate="txtNums" Display="None" ErrorMessage="数量输入有误，请重新输入！" ID="revNums" ValidationExpression="\d*(\.\d*)?" ValidationGroup="gSubmit" runat="server"></asp:RegularExpressionValidator>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            单件毫米数
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label CssClass="fullWidth" ID="lblSingleMMNumber" Width="80px" runat="server" Text='<%#Eval("SingleMMNumber") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            毫米数
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:TextBox CssClass="fullWidth" ID="txtMMNumber" Width="80px" runat="server" onkeyup="CheckNumWithDot(this);" Text='<%#Eval("MMNumber") %>'></asp:TextBox>
                                            <asp:RegularExpressionValidator ControlToValidate="txtMMNumber" Display="None" ErrorMessage="数量输入有误，请重新输入！" ID="revMMNumber" ValidationExpression="\d*(\.\d*)?" ValidationGroup="gSubmit" runat="server"></asp:RegularExpressionValidator>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            单价
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:TextBox CssClass="fullWidth" ID="txtPrice" Width="80px" runat="server" onkeyup="CheckNumWithDot(this);changeNum(this,'txtPrice');" Text='<%#Eval("Price") %>'></asp:TextBox>
                                            <asp:RegularExpressionValidator ControlToValidate="txtPrice" Display="None" ErrorMessage="单价输入有误，请重新输入！" ID="revPrice" ValidationExpression="\d*(\.\d*)?" ValidationGroup="gSubmit" runat="server"></asp:RegularExpressionValidator>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            金额
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:TextBox CssClass="lblreadonly" ID="txtAmount" Width="80px" runat="server" Text='<%#Eval("Amount") %>'></asp:TextBox>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            预计交期
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <input class="Wdate" id="cpExpectDate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="true" runat="server" type="text"></input>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderStyle Width="35px" />
                                        <ItemStyle Width="35px" />
                                        <HeaderTemplate>
                                            删除
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:ImageButton ImageUrl="~/App_Themes/Common_CSS/images/delete_small.gif" runat="server"
                                                ID="ibtnDel" /><asp:Button ID="btnDel" runat="server" CssClass="Hidden" CommandArgument='<%#Eval("MaterialID") %>'
                                                    CommandName="del" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:SGridView>
                        </div>
                    </div>
                </div>
            </div>
            <div class="controlBar" align="center">
                <table cellpadding="0" cellspacing="0" style="width: 300px; margin: 0 auto;">
                    <tr>
                        <td colspan="4">
                            <label class="btnStyleb png_bg">
                                <asp:Button ID="btnSubmit" runat="server" Text="确定"
                                    OnClick="btnSubmit_Click" ValidationGroup="gSubmit" />
                            </label>
                            <label class="btnStylec png_bg">
                                <input type="button" id="Button2" value="返回" runat="server" onclick="window.location = 'PurchaseList.aspx'" />
                            </label>
                        </td>
                    </tr>
                </table>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>